package mian

import (
	"sync"
	"sync/atomic"
)

// 单例模式

type DBPool struct{}

var dbPoolIns *DBPool

var lock sync.Mutex

var initialed uint32

func GetDBPool() *DBPool {
	// 双重锁定
	if atomic.LoadUint32(&initialed) == 1 {
		return dbPoolIns
	}
	lock.Lock()
	defer lock.Unlock()
	if initialed == 0 {
		dbPoolIns = &DBPool{}
		atomic.StoreUint32(&initialed, 1)
	}
	return dbPoolIns
}

var once sync.Once

func GetDBPool2() *DBPool {
	once.Do(func() {
		dbPoolIns = &DBPool{}
	})
	return dbPoolIns
}
